package com.wxh.producerconsumer.lockprocess;

/**
 * @ClassName: LockTest
 * @Description: 锁机制测试
 * @Author wxh
 * @Date: 2021/12/7 15:11
 * @Version V1.0.0
 * @Since 1.8
 */
public class LockTest {
    public static void main(String[] args) {
        Resource resource = new Resource();
        new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                try {
                    resource.produce();
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }, "生产者 A").start();

        new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                try {
                    resource.produce();
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }, "生产者 B").start();

        new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                try {
                    resource.consume();
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }, "消费者 A").start();

        new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                try {
                    resource.consume();
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }, "消费者 B").start();
    }
}
